package com.ruoyi.training.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.ServletUtils;
import com.ruoyi.system.api.model.LoginUser;
import com.ruoyi.training.dto.certificate.SpecialCertificateDto;
import com.ruoyi.training.dto.certificate.SpecialCertificateImport;
import com.ruoyi.training.dto.registration.RegistrationImport;
import com.ruoyi.training.service.ISpecialCertificateService;
import com.ruoyi.training.vo.certificate.SpecialCertificateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.SpecialCertificate;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 特设证书管理Controller
 * 
 * @author hcc
 * @date 2025-11-06
 */
@RestController
@RequestMapping("/specialCertificate")
public class SpecialCertificateController extends BaseController
{
    @Autowired
    private ISpecialCertificateService specialCertificateService;

    /**
     * 查询特设证书管理列表
     */
    @RequiresPermissions("training:specialCertificate:list")
    @GetMapping("/list")
    public TableDataInfo list(SpecialCertificate specialCertificate)
    {
        startPage();
        List<SpecialCertificate> list = specialCertificateService.selectSpecialCertificateList(specialCertificate);
        return getDataTable(list);
    }

    /**
     * 导出特设证书管理列表
     */
    @RequiresPermissions("training:specialCertificate:export")
    @Log(title = "特设证书管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpecialCertificate specialCertificate)
    {
        List<SpecialCertificate> list = specialCertificateService.selectSpecialCertificateList(specialCertificate);
        ExcelUtil<SpecialCertificate> util = new ExcelUtil<SpecialCertificate>(SpecialCertificate.class);
        util.exportExcel(response, list, "特设证书管理数据");
    }

    /**
     * 获取特设证书管理详细信息
     */
    @RequiresPermissions("training:specialCertificate:query")
    @GetMapping(value = "/{specialCertificateId}")
    public AjaxResult getInfo(@PathVariable("specialCertificateId") String specialCertificateId)
    {
        return success(specialCertificateService.selectSpecialCertificateBySpecialCertificateId(specialCertificateId));
    }

    /**
     * 新增特设证书管理
     */
    @RequiresPermissions("training:specialCertificate:add")
    @Log(title = "特设证书管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpecialCertificate specialCertificate)
    {
        return toAjax(specialCertificateService.insertSpecialCertificate(specialCertificate));
    }

    /**
     * 修改特设证书管理
     */
    @RequiresPermissions("training:specialCertificate:edit")
    @Log(title = "特设证书管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpecialCertificate specialCertificate)
    {
        return toAjax(specialCertificateService.updateSpecialCertificate(specialCertificate));
    }

    /**
     * 删除特设证书管理
     */
    @RequiresPermissions("training:specialCertificate:remove")
    @Log(title = "特设证书管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{specialCertificateIds}")
    public AjaxResult remove(@PathVariable String[] specialCertificateIds)
    {
        return toAjax(specialCertificateService.deleteSpecialCertificateBySpecialCertificateIds(specialCertificateIds));
    }

    /**
     * 查询特设证书管理列表
     */
    @RequiresPermissions("training:specialCertificate:list")
    @GetMapping("/getSpecialList")
    public TableDataInfo getSpecialList(SpecialCertificateVo specialCertificateVo)
    {
        startPage();
        List<SpecialCertificateDto> list = specialCertificateService.getSpecialCertificateList(specialCertificateVo);
        return getDataTable(list);
    }

    @Log(title = "导入证书信息", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<SpecialCertificateImport> util = new ExcelUtil<SpecialCertificateImport>(SpecialCertificateImport.class);
        List<SpecialCertificateImport> certificateImportList = util.importExcel(file.getInputStream());
        String message = specialCertificateService.importCertificate(certificateImportList);
        return AjaxResult.success(message);
    }
}
